package com.uaroadshow.entity.user;

import java.beans.Transient;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "user")
@JsonIgnoreProperties(value = { "hibernate_lazy_initializer", "handler", "fieldHandler" })
public class User {
    
    @Id
    @GeneratedValue
    private Long id;

    private String mobile;
    
    private String openid;
    
    private String unionid;
    
    private String name;
    
    private String nickname;
    
    private String avatar;
    
    private String email;
    
    private Date createTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * 是否是管理员
     */
    @Column(name = "is_admin")
    private boolean admin;
    
    /**
     * 是否是子账户
     */
    @Column(name = "is_children")
    private boolean children; 
    
    /**
     * The default constructor
     */
    public User() {
    
    }
    
    /**
     * 
     * @param unionid
     * @param openid
     * @param mobile
     */
    public User(String unionid, String openid, String mobile) {
        this.unionid = unionid;
        this.openid = openid;
        this.mobile =  mobile;
        this.createTime = new Date();
    }
    
    /**
     * @param mobile
     * @return
     */
    public User editMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }
    
    /**
     * 
     * @param openid
     * @return
     */
    public User bindOpenid(String openid) {
        this.openid = openid;
        return this;
    }
    
    /**
     * 
     * @param email
     * @return
     */
    public User bindEmail(String email) {
        this.email = email;
        return this;
    }
    
    /**
     * 
     * @param mobile
     * @return
     */
    public User bindMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public User changeToChild() {
    	this.children = true;
    	return this;
    }
    
    /**
     * 
     * @param nickname
     * @param avatar
     * @return
     */
    public User initliaze(String nickname, String avatar) {
        this.nickname = nickname;
        this.avatar = avatar;
        
        return this;
    }

    /**
     * 
     * @return
     */
    @Transient
    public boolean hasEmail() {
        return StringUtils.isNotEmpty(this.email);
    }

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the mobile
	 */
	public String getMobile() {
		return mobile;
	}

	/**
	 * @return the openid
	 */
	public String getOpenid() {
		return openid;
	}

	/**
	 * @return the unionid
	 */
	public String getUnionid() {
		return unionid;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the nickname
	 */
	public String getNickname() {
		return nickname;
	}

	/**
	 * @return the avatar
	 */
	public String getAvatar() {
		return avatar;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @return the disabled
	 */
	public boolean isDisabled() {
		return disabled;
	}

	/**
	 * @return the admin
	 */
	public boolean isAdmin() {
		return admin;
	}

	/**
	 * @return the children
	 */
	public boolean isChildren() {
		return children;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param mobile the mobile to set
	 */
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	/**
	 * @param openid the openid to set
	 */
	public void setOpenid(String openid) {
		this.openid = openid;
	}

	/**
	 * @param unionid the unionid to set
	 */
	public void setUnionid(String unionid) {
		this.unionid = unionid;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param nickname the nickname to set
	 */
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	/**
	 * @param avatar the avatar to set
	 */
	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @param disabled the disabled to set
	 */
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	/**
	 * @param admin the admin to set
	 */
	public void setAdmin(boolean admin) {
		this.admin = admin;
	}

	/**
	 * @param children the children to set
	 */
	public void setChildren(boolean children) {
		this.children = children;
	}
}
